<layout name="page" />
<block name="content">
	{:widget('page_header/simple',array('name'=>'职员查询index2'))}
	<div class="row">
		<div class="col-sm-12 sub-sidebar">
			<div class="row">
				<div class="col-xs-3">
					<a onclick="go_back()" class="btn btn-primary"><i class="fa fa-reply"></i></a>
				</div>
				<div class="col-xs-6 text-center">
					<h4 id="dept_name"></h4>
				</div>
				<div class="col-xs-3 text-right">
					已选：<span id="data_count">0</span>
				</div>
			</div>
			<div class="well">
				<?php echo $menu ?>
			</div>
		</div>
		<select class="hidden" id="data"></select>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var $return_dept_id;
		function go_back() {
			if ($dept_pid_id != undefined) {
				$return_dept_id = $dept_pid_id;
				$("ul.tree_menu li").hide();
				$("ul.tree_menu li.dept_pid_" + $return_dept_id).show();
				$dept_name = $("ul.tree_menu li.dept_" + $return_dept_id + "> a").text();
				$dept_pid_id = $("ul.tree_menu li.dept_" + $return_dept_id).attr('dept_pid_id');
				$("#dept_name").text($dept_name);
			}			
		}

		function btn_local_search() {
			$(".sub-sidebar .tree_menu a").each(function() {
				$(this).attr("class", "");
			});
			send_ajax("{:url('read')}", "keyword=" + $("#keyword").val(), function(data) {
				show_data(data);
			});
			return false;
		}

		function key_local_search() {
			$(".sub-sidebar .tree_menu a").each(function() {
				$(this).attr("class", "");
			});
			if (event.keyCode == 13) {
				send_ajax("{:url('read')}", "keyword=" + $("#keyword").val(), function(data) {
					show_data(data);
				});
			}
			return false;
		}

		$(document).ready(function() {
			$("ul.tree_menu li").hide();
			$("ul.tree_menu li.level_1").show();

			$("ul.tree_menu li.dept").click(function() {
				$("ul.tree_menu li").hide();
				$dept_id = $(this).attr("dept_id");
				$dept_name = $(this).text();
				$dept_pid_id = $(this).attr("dept_pid_id");
				$return_dept_id = $dept_pid_id;
				$('#dept_name').text($dept_name);
				$("ul.tree_menu li.dept_pid_" + $dept_id).show();
			});

			$("ul.tree_menu li.emp").click(function() {
				if ($("a", this).hasClass('active')) {
					$("a", this).removeClass('active');
					$val = $(this).attr('user_id');
					$("#data  option[value='" + $val + "']").remove();
					$("#data_count").text($("#data option").length);
				} else {
					$("a", this).addClass('active');
					$text = $(this).text();
					$val = $(this).attr('user_id');
					if ($("#data  option[value='" + $val + "']").val() == undefined) {
						$("<option></option>").val($val).text($text).appendTo("#data");
						$("#data_count").text($("#data option").length);
					};
				}
			});
		});

	</script>
</block>